#!/bin/bash

SERVER_PROGRAM="pro_server"
CURRENT_PATH=$(pwd)
SRC_PATH="$CURRENT_PATH/src/"
INC_PATH="$CURRENT_PATH/include/"
SQL_PATH="$CURRENT_PATH/../sqlite/include"
SOURCE_FILE="main.c"
LIBSQL="-L../sqlite/lib -lsqlite3"
CLISQL="-L $CURRENT_PATH/install/libs -lserver"

echo "正在编译并连接库生成可执行程序..."
gcc "$SOURCE_FILE" -I "$INC_PATH" -I "$SQL_PATH" $CLISQL $LIBSQL -o "$SERVER_PROGRAM"

# 检查编译是否成功
if [ $? -ne 0 ]; then
	echo "编译失败，请检查代码和库的配置。"
	exit 1
fi

echo "可执行程序 $SERVER_PROGRAM 已成功生成。"
export LD_LIBRARY_PATH=`pwd`/../sqlite/lib/:$LD_LIBRARY_PATH

echo "执行程序"
./"$SERVER_PROGRAM" -p 8888

